import React from 'react'
import { Button, Select } from 'antd'
import '../SecondPages/SecondPages.css'
import {
  findConfig,
  devProTest,
  getHeaderParams,
} from '../../rudexRou/OperatesCookie.js'
const HasPermi = (props) => {
  let menuList = []
  if (devProTest() === 'develop') {
    const menuList1 = localStorage.getItem('config')
      ? findConfig(localStorage.getItem('config'), 616, null)
      : []
    menuList1.forEach((item) => {
      menuList = item ? menuList.concat(item.sonMenus) : menuList
    })
  } else {
    let pathObj = getHeaderParams()
    menuList = localStorage.getItem('config')
      ? findConfig(
          localStorage.getItem('config'),
          pathObj.parentId == -1 ? pathObj.menuId : pathObj.parentId,
          pathObj.parentId == -1 ? pathObj.parentId : null
        )
      : []
  }
  if (!menuList) {
    return null
  }
  let resourceList = []
  menuList.forEach((item) => {
    resourceList = item ? resourceList.concat(item.sonMenus) : resourceList
  })
  if (
    resourceList &&
    resourceList.find((item) => {
      if (item && props.bottonData) {
        return item.interceptor === props.bottonData.interceptor
      } else {
        return false
      }
    })
  ) {
    return (
      <Button
        type={props.bottonData.type}
        onClick={props.bottonData.clickFn}
        icon={props.bottonData.icon}
      >
        {props.bottonData.text}
      </Button>
    )
  } else {
    return null
  }
}

export default HasPermi
